package com.niit.controller;

import com.niit.bean.Person;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @ProjectName: springBoot3-demo
 * @Package: com.niit.controller
 * @ClassName: ThymeleafController
 * @Author: zjh
 * @description: TODO
 * @date: 2024/1/3 10:31
 * @version: 1.0
 */
@Controller
public class ThymeleafController {
    @GetMapping("/home")
    public String home(@RequestParam("name") String name, Model model)
    {
        model.addAttribute("msg","我是一条新消息");
        model.addAttribute("name",name);
        String text = "<span style='color:red'>"+name+"</span>";
        model.addAttribute("text",text);

        model.addAttribute("imgUrl","/5.jpg");
        model.addAttribute("style","width:300px");
        model.addAttribute("show",true);

        Person person = new Person(1L,"张XX","123@qq.com",18,"HR");
        model.addAttribute("person",person);

        return "home";
    }

    @GetMapping("/list")
    public String personList(Model model){
        List<Person> list = new ArrayList<Person>();
        list.add(new Person(1L, "张三", "", 15,"pm"));
        list.add(new Person(3L, "李四", "zs2@qq.com", 16,"pm"));
        list.add(new Person(4L, "王五", "zs3@qq.com", 17,"pm"));
        list.add(new Person(7L, "张XX", "zs4@qq.com", 18,"admin"));
        list.add(new Person(8L, "王XX", "zs5@qq.com", 19,"hr"));
        model.addAttribute("persons",list);
        return  "list";
    }
}
